docker run, create: add shell completion for CDI devices for "--device"#6450
docker run, create: add shell completion for CDI devices for "--device"#6450thaJeztah wants to merge 2 commits intodocker:masterfrom
Conversation
With this patch:
docker info --format '{{json .DiscoveredDevices}}'
[{"Source":"cdi","ID":"docker.com/gpu=webgpu"}]
docker container create --device=<tab>
docker container create --device=docker.com/gpu=webgpu
docker run --device=docker.com/gpu=webgpu
docker run --device=<tab>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| func completeCDIDevices(dockerCLI completion.APIClientProvider) cobra.CompletionFunc { | ||
| return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
| if strings.HasPrefix(toComplete, "/") { | ||
| return nil, cobra.ShellCompDirectiveDefault | cobra.ShellCompDirectiveNoSpace | ||
| } | ||
|
|
||
| info, err := dockerCLI.Client().Info(cmd.Context()) |
There was a problem hiding this comment.
Opening as draft, because I had this branch but after implementing CDI completion, I realised we also need to provide completion for file-paths (assuming the daemon and CLI are on the same host), so we need some solid way to distinguish "user wants to complete a CDI device" vs "user wants to add a device (e.g. /dev/foo:/some/path).
cli/command/container/completion.go
Outdated
| devices = append(devices, di.ID) | ||
| devices = append(devices, cobra.CompletionWithDesc(di.ID, "CDI device")) |
There was a problem hiding this comment.
Still on the fence if cobra.CompletionWithDesc is a bit "too much"; it's the equivalent of <value> + \t + <description>. I guess it's slightly more expressive, but also makes it look more magical than it is 😂
--deviceshell completion #6152docker run, create: add shell completion for CDI devices for "--device"
With this patch:
- How to verify it
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)